
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int n;
int y;

int ret;

int a;
int _y;

int main()
{
	cin>>y>>n;
	for(ret=0;ret!=n;y++,a++)
	{
		int s_year = y;
		int ans[10]={0};
		for(ret =0;s_year!=0;s_year/=10)
		{
			if(ans[s_year%10]++ == 0)
				ret++;
		}
		if(y/1000==0&&ans[0]==0)
		{
			ret++;
		}
	}
	printf("%d %04d",--a,--y);
	return 0;
}
